<template>
	<view class="container">
		<view class="banner">
			<u-swiper :list="list" :height="350"></u-swiper>
		</view>
		<view class="list">
			<view class="lists" @click="shop_cart(index)" v-for="(item,index) in menulist" :key="index">
				<image :src="item.image" mode="" class="lists_img"></image>
				<p class="lists_p">{{item.name}}</p>
			</view>
		</view>
		<view class="qianyue" @click="vip">
			<image src="../../static/images/qianyue.png" mode=""></image>
		</view>
		<view class="task" @click="sort">
			<image src="../../static/images/task.png" mode="" class="task_img"></image>
		</view>
		<view class="yun" style="padding: 0 50rpx;">
			<u-form-item :label-position="labelPosition" label="开启云端执行" prop="remember" label-width="200">
				<u-switch v-model="remember" slot="right" @change="switchChange"></u-switch>
			</u-form-item>
		</view>
		<view class="cooperation">
			<view class="cooperation_title">
				第三方合作
			</view>
			<view class="Thirdparty">
				<view class="icons" @click="awaken1">
					<image src="../../static/images/douyin.png" mode=""></image>
					<p class="icons_p">抖音</p>
				</view>
				<view class="icons" @click="awaken3">
					<image src="../../static/images/861464c4f45543b7a0fb64be610d64b.jpg" mode=""></image>
					<p class="icons_p">西瓜</p>
				</view>
				<!-- <view class="icons" @click="awaken3" style="width: 25%;margin-right: 100rpx;">
					<image src="../../static/images/aa3527f901d68196e08616ea6d462ee.png" mode=""></image>
					<p class="icons_p">鑫亿直播</p>
				</view> -->
				<view class="icons" @click="awaken2">
					<image src="../../static/images/jinri.png" mode=""></image>
					<p class="icons_p">今日</p>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMenu
	} from '@/api/store';
	import {
		postcenter,getUser,config
	} from '@/api/user';
	export default {
		data() {
			return {
				list: [{
						image: '../../static/images/40147e1489a9bd7fdaa137016f0bea1.jpg'
					},
					{
						image: '../../static/images/9bf6add64aede1fd41d596c7905d7b1.jpg'
					},
					{
						image: '../../static/images/e471a656fc5b4386a388cfb9e57878a.jpg'
					}
				],
				menulist: [],
				labelPosition: 'left',
				remember: false,
				auto_task:0
			}
		},
		onLoad() {
			
			var _this = this;
			// 获取手机状态栏高度
			uni.getSystemInfo({
				success: function(data) {
					// 将其赋值给this
					// _this.height = data.statusBarHeight;
					// console.log(data.statusBarHeight)
				}
			})
			// this.awaken1()
			this.User()
			// if(this.auto_task==0){
			// 	this.remember=false
			// }else{
			// 	this.remember=true
			// }
		},
		onShow() {
			this.getIsNews()
			this.User()
			this.gethomes()
			console.log(123)
			// console.log(this.remember)
			// if(uni.getStorageSync('status')){
			// 	let data={
			// 		auto_task:1
			// 	}
			// 	postcenter(data).then(res => {
			// 		console.log(res)
			// 	})
			// }else{
			// 	let data={
			// 		auto_task:0
			// 	}
			// 	postcenter(data).then(res => {
			// 		console.log(res)
			// 	})
			// }
			
		},

		methods: {
			getIsNews() {
				let version=""
				let _this=this
				config().then(res=>{
					this.version=res.data.app_version
					console.log(_this.version)
					uni.getSystemInfo({
					    success: (res) => {
							
					        //检测当前平台，如果是安卓则启动安卓更新  
					        if (res.platform == "android") {
					            // 判断版本问题
								console.log("android")
					            plus.runtime.getProperty(plus.runtime.appid, (info) => {
					                console.log(version > parseFloat(info.version))
					                if (_this.version > parseFloat(info.version)) {
					                    // this.doUpData()
					                    uni.showModal({
					                        title: '版本发布更新',
					                        content: '发现新版本，请进行更新',
					                        confirmText: '更新',
					                        confirmColor: '#EE8F57',
					                        success: function(res) {
					                            if (res.confirm) {
					                                uni.navigateTo({
					                                    url: "../appDown/appDown",
					                                });
					                            }
					                        }
					                    });
					                }
					            });
					        } 
					    }
					})
				})
			},
			User(){
				getUser().then(res=>{
					// console.log(res.data.auto_task)
					this.auto_task=res.data.auto_task
					if(this.auto_task==0){
						this.remember=false
					}else{
						this.remember=true
					}
				})
			},
			switchChange(status) {
				console.log(status);
				// uni.setStorage({
				//     key: 'status',
				//     data: status,
				// });
				console.log(this.auto_task)
				if(this.auto_task==0){
					postcenter().then(res => {
						console.log(res)
						// this.User()
					})
				}else{
					postcenter().then(res => {
						console.log(res)
						// this.User()
					})
				}
			},
			gethomes() {
				getMenu().then(res => {
					this.menulist = res.data
					// console.log(res.data)
				}, err => {})
			},
			vip() {
				uni.navigateTo({
					url: "../user_vip/user_vip"
				})
			},
			shop_cart(index) {
				if (index == 0) {
					uni.switchTab({
						url: "../shop_cart/shop_cart"
					})
				} else if (index == 1) {
					uni.navigateTo({
						url: "./ranking"
					})
				} else if (index == 2) {
					uni.navigateTo({
						url: "../bundle/user_wallet/user_wallet"
					})
				}else if (index == 3){
					uni.navigateTo({
						url: "../bundle/contact_offical/contact_offical2"
					})
				}

			},
			sort() {
				uni.switchTab({
					url: '/pages/sort/sort'
				});
			},
			awaken1() {
				// console.log(123)
				// // plus.runtime.openURL('snssdk1128://user/profile/id?refer=web&gd_label=click_wap_profile_follow&type=need_follow&needlaunchlog=1');
				// let url = "snssdk1128://aweme/detail/6534452667488406792?refer=web&gd_label=click_wap_detail_download_feature&appParam=%7B%22__type__%22%3A%22wap%22%2C%22position%22%3A%22900718067%22%2C%22parent_group_id%22%3A%226553813763982626051%22%2C%22webid%22%3A%226568996356873356814%22%2C%22gd_label%22%3A%22click_wap%22%7D&needlaunchlog=1"
				// window.location.href = "https://www.douyin.com/home";
				if (plus.os.name == 'Android') {
					//安卓
					if (
						plus.runtime.isApplicationExist({
							//查看安卓系统手机有没有下载这款app
							pname: 'com.ss.android.ugc.aweme' //微信app云打包的包名
						})
					) {
						//安装了app
						// plus.runtime.openURL(
						// 	'snssdk1128://',
						// 	//抖音
						// 	function(res) {
						// 		console.log(res);
						// 	}
						// );
						plus.runtime.launchApplication({
								pname: 'com.ss.android.ugc.aweme'
							},
							function(e) {
								console.log('Open system default browser failed: ' + e.message);
							}
						);
					} else {
						//未安装app
						uni.showModal({
							title: '提示',
							content: '您还没有此APP,去下载',
							success: function(res) {
								if (res.confirm) {
									plus.runtime.openURL('https://www.douyin.com/home', function(res) {
										console.log(res);
									});
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				}
			},
			awaken2() {
				console.log(123)
				// // plus.runtime.openURL('snssdk1128://user/profile/id?refer=web&gd_label=click_wap_profile_follow&type=need_follow&needlaunchlog=1');
				// let url = "snssdk1128://aweme/detail/6534452667488406792?refer=web&gd_label=click_wap_detail_download_feature&appParam=%7B%22__type__%22%3A%22wap%22%2C%22position%22%3A%22900718067%22%2C%22parent_group_id%22%3A%226553813763982626051%22%2C%22webid%22%3A%226568996356873356814%22%2C%22gd_label%22%3A%22click_wap%22%7D&needlaunchlog=1"
				// window.location.href = "https://www.douyin.com/home";
				if (plus.os.name == 'Android') {
					//安卓
					if (
						plus.runtime.isApplicationExist({
							//查看安卓系统手机有没有下载这款app
							pname: 'com.ss.android.article.news' //微信app云打包的包名
						})
					) {
						//安装了app
						plus.runtime.launchApplication({
								pname: 'com.ss.android.article.news'
							},
							function(e) {
								console.log('Open system default browser failed: ' + e.message);
							}
						)
					} else {
						//未安装app
						uni.showModal({
							title: '提示',
							content: '您还没有此APP,去下载',
							success: function(res) {
								if (res.confirm) {
									plus.runtime.openURL(
										'https://aisite.wejianzhan.com/site/wjzdk1aw/834b7cf4-3491-4920-8540-9de8ae8904d7?fid=nH04nWb4rjbYPWRzPjTYnjmzP1PxrHDsPWDvg1D&ch=45',
										function(res) {
											console.log(res);
										});
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				}
			},
			awaken3() {
				console.log(123)
				// // plus.runtime.openURL('snssdk1128://user/profile/id?refer=web&gd_label=click_wap_profile_follow&type=need_follow&needlaunchlog=1');
				// let url = "snssdk1128://aweme/detail/6534452667488406792?refer=web&gd_label=click_wap_detail_download_feature&appParam=%7B%22__type__%22%3A%22wap%22%2C%22position%22%3A%22900718067%22%2C%22parent_group_id%22%3A%226553813763982626051%22%2C%22webid%22%3A%226568996356873356814%22%2C%22gd_label%22%3A%22click_wap%22%7D&needlaunchlog=1"
				// window.location.href = "https://www.douyin.com/home";
				if (plus.os.name == 'Android') {
					//安卓
					if (
						plus.runtime.isApplicationExist({
							//查看安卓系统手机有没有下载这款app
							pname: 'com.ss.android.article.video' //微信app云打包的包名
						})
					) {
						//安装了app
						// plus.runtime.openURL(
						// 	'snssdk32://',
						// 	//西瓜视频
						// 	function(res) {
						// 		console.log(res);
						// 	}
						// );
						plus.runtime.launchApplication({
								pname: 'com.ss.android.article.video',
							
							},
							function(e) {
								console.log('Open system default browser failed: ' + e.message);
							}
						);
					} else {
						//未安装app
						uni.showModal({
							title: '提示',
							content: '您还没有此APP,去下载',
							success: function(res) {
								if (res.confirm) {
									plus.runtime.openURL(
										'https://z.ixigua.com/yvkw',
										function(res) {
											console.log(res);
										});
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				}
			}
			
		}
	}
</script>

<style lang="less" scoped>
	* {
		margin: 0;
		padding: 0;
	}

	.container {
		background: #FFFFFF;

		.banner {
			padding: 20rpx 40rpx;
			height: 400rpx;
			background: linear-gradient(#f53b35, #ffffff);
		}

		.list {
			height: 100px;
			padding: 0 20rpx;
			display: flex;

			.lists {
				width: 25%;
				text-align: center;
				padding: 20rpx 0;

				// background: #FFFFFF;
				.lists_img {
					width: 100rpx;
					height: 100rpx;
				}

				.lists_p {
					margin-top: 15rpx;
					font-size: 30rpx;
					font-weight: bold;
				}
			}
		}

		.qianyue {
			padding: 0 30rpx;

			image {
				width: 100%;
				height: 250rpx;
			}
		}

		.task {
			padding: 0 40rpx;

			.task_title {
				color: #91949e;
				font-weight: bold;

				text {
					font-size: 30rpx;
					color: #FA3534;
					margin-left: 10rpx;
				}
			}

			.task_img {
				margin-top: 30rpx;
				width: 100%;
				height: 200rpx;
			}
		}

		.cooperation {
			margin-top: 50rpx;
			padding: 0 40rpx;

			.cooperation_title {
				font-size: 45rpx;
				font-weight: bold;
			}

			.Thirdparty {
				display: flex;
				justify-content: space-between;
			}

			.icons {
				margin-top: 50rpx;
				// margin-left: 50rpx;
				width: 100rpx;
				text-align: center;

				image {
					width: 100rpx;
					height: 100rpx;
				}

				.icons_p {
					margin-top: 20rpx;
					font-size: 30rpx;
					font-weight: bold;
				}
			}
		}
	}
</style>
